 
 	<?php
		function set_val($obj, $val, $return='echo')
		{
			if(isset($obj))
				if(isset($obj->$val))
					if($return=='echo')
						echo($obj->$val);
					else
						return $obj->$val;
		}
	?>
 
				<div><br>
					<form id="form" class="block-content form" action="<?php echo site_url('admin/user/save')?>" method="post">
						<input type="hidden" id="id" name="id" value="<?php set_val($user,'id')?>" />
						<div class="_50">
							<p><label for="first_name">First Name</label>
							<input id="first_name" name="first_name" class="required" type="text" value="<?php set_val($user,'first_name')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="last_name">Last Name</label>
							<input id="last_name" name="last_name" class="required" type="text" value="<?php set_val($user,'last_name')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="email">Email</label>
							<input id="email" name="email" class="required email" type="text" value="<?php set_val($user,'email')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="username">User Name</label>
							<input id="username" name="username" class="required" type="text" value="<?php set_val($user,'username')?>" /></p>
						</div>
						
						<div class="_100">
							<p><label for="role_id">User Role</label>
							<select id="role_id" name="role_id">
								<?php foreach($roles as $role):?>
								<option value="<?php echo $role->role_id?>" <?php echo (isset($user->role_id) && $user->role_id==$role->role_id ? 'selected="selected"' : ($role->default == 1 && !isset($user->role_id) ? 'selected="selected"' : ''))?> ><?php echo $role->role_name?></option>
								<?php endforeach;?>
							</select>
							</p>
						</div>
						
						<div class="_50">
							<p><label for="password">Password</label>
							<input id="password" name="password" class="required" type="password" value="<?php set_val($user,'password')?>" /></p>
						</div>
						
						<div class="_50">
							<p><label for="repassword">Re Enter Password</label>
							<input id="repassword" name="repassword" class="required" type="password" value="<?php set_val($user,'password')?>" /></p>
						</div>
						
						
						
						

						<div class="clear"></div>
						<div class="block-actions">
							<ul class="actions-left">
								<li><a class="button red" id="reset-validate-form" href="javascript:void(0);">Reset</a></li>
							</ul>
							<ul class="actions-right">
								<li><input type="submit" class="button" value="Save!"></li>
							</ul>
						</div>
					</form>

				</div>
				
				
	<script type="text/javascript">
						
		
	$().ready(function() {
		
		/** Submit Form **/
		$("#form").validate({
				rules:{},
				messages: {},
				submitHandler: function(form) {
				   //submit
				$.post("<?php echo site_url('admin/user/save')?>", $("#form").serialize(),
					function(data){
						if(data){
							
							newdata = $.parseJSON(data);
							
							if(newdata.error){
								Gtheme = 'error';
								
								$.each(newdata.msg, function(index) {
									$.jGrowl(newdata.msg[index], { theme: Gtheme,position:'center'  });
								});

							}
							else{
								Gtheme = 'saved';
								$.jGrowl(newdata.msg, { theme: Gtheme,position:'center'  });
								$('.a-z-list').parent().children('.block-content').slideToggle();
								a_z_list();
								temp_id = $("#id").val();
								//clear the folrm
									$("#id").val('');
									$(":input").not(":button, :submit, :reset, :hidden").each(function () {
										this.value = '';
									});
								load_form(temp_id);
							}

						}
						else{
							$.jGrowl("Error!", { theme: 'error' });
						}
					});
				}
			});
		/** End Submit Form **/
		
		});
		
		
    </script>

